package org.springframework.social.connect.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionData;
import org.springframework.social.dao.ConnectionDataDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.MultiValueMap;

@Service("connectionDataService")
public class ConnectionDataServiceImpl implements ConnectionDataService
{

	@Autowired
	private ConnectionDataDao connectionDataDao;

	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public List<ConnectionData> findConnectionDataByUserId(String userId)
	{
		String queryString = "select cd from ConnectionData cd where cd.id.userId = :userId order by cd.id.providerId, cd.rank";
		List<ConnectionData> list = connectionDataDao.findByNamedParam(queryString, "userId", userId);
		return list;
	}

	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public List<ConnectionData> findConnectionDataByUserIdProviderId(String userId, String providerId)
	{
		String queryString = "select cd from ConnectionData cd where cd.id.userId = :userId and cd.id.providerId = :providerId order by cd.rank";
		List<ConnectionData> list = connectionDataDao.findByNamedParam(queryString, new String[] { "userId", "providerId" }, new Object[] { userId,
				providerId });
		return list;
	}

	public MultiValueMap<String, Connection<?>> findConnectionsToUsers(MultiValueMap<String, String> providerUsers, String userId)
	{

		return null;
	}

}
